<?php

namespace App\Jobs;

use App\Mail\ResetPassword;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;

class SendResetPassEmail implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;
    protected $_user;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($_userInfo)
    {
        $this->_user = $_userInfo;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        try {
            Mail::to($this->_user['email'])->send(new ResetPassword($this->_user));
        } catch (\Exception $mailEx) {
            // todo write error to log
            logger($mailEx->getMessage());
        }
    }
}
